package com.example.sisko_database;

import java.io.IOException;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class DatabaseInsert {

	private DatabaseInit myDbHelper;
	private SQLiteDatabase database;
	private long contactID;
	private long ratingID;
	
	//opening the database
	public DatabaseInsert(Context context) {
		myDbHelper = new DatabaseInit(context);
	
		try {
		  
			myDbHelper.createDataBase();
		  
		} catch (IOException ioe) {
		
			throw new Error("Unable to create database");
		  
		}
	  
		try {
		  
			database = myDbHelper.openDataBase();
		
		  
		}catch(SQLException sqle){
		  
			throw sqle;
		 
		}
	}
	
	//closing the database
	public void close(){
		database.close();
	}
	
	//insert new Item (Restaurant, Cafe, CLub, Bar) into database
	public void insertNewItem(Double Long, Double Lat, String Phone,
			String street, int house_number, String zip, String city){
		
		ContentValues value = new ContentValues();
		
		value.put("latitutde", Lat);
		value.put("longitude", Long);
		value.put("phone", Phone);
		value.put("street", street);
		value.put("house_number", house_number);
		value.put("city", city);
		value.put("zip", zip);
				
		contactID = database.insert("TABLE_CONTACT", null, value);
	}
	
	//insert new Item (favorite, rating_bar) into database
	public void insertNewItem2(){
		
		ContentValues value = new ContentValues();
		
		value.put("favorit", 0);
		value.put("rating_bar", 0);
		
		ratingID = database.insert("TABLE_RATING", null, value);
		
	}
	
	//insert new Item3 (category, name, picture, id's) into database
	public void insertNewItem3(String category, String pic, String name){
		
		ContentValues value = new ContentValues();
	
		value.put("name", name);
		value.put("category", category);
		value.put("picture", pic);
		value.put("contact_id", contactID);
		value.put("rating_id", ratingID);
		
		database.insert("TABLE_LOCATION", null, value);
	}
}
	

